<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>register</title>

    <!-- Bootstrap -->
    <link href="/finder/Public/Css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/finder/Public/Css/header.css"/>
    <!--     <link rel="stylesheet" href="/finder/Public/Static/validator/jquery.validator.css"/>
    -->    <link href="/finder/Public/Css/register.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<header role="navigation" class="header">
    <div class="container">
        <div class="row">
            <div class="col-md-2 col-sm-2 .navbar-left">
                <a href="<?php echo U('Home/Index/index');?>" class="logo">
                    <img src="/finder/Public/Img/logo-finder.png" alt="logo" class="logo1">
                </a>
            </div>
            <div class="col-md-8 col-sm-8 text-center">
                <div class="collapse navbar-collapse" id="main-menu">
                    <ul class="menu">
                        <li id="index" role="presentation"><a href="<?php echo U('Home/Index/index');?>"><span>首页</span></a></li>
                        <li id="publish" role="presentation"><a href="<?php echo U('Home/Blog/publish');?>"><span>发布</span></a></li>
                        <li id="blog" role="presentation"><a href="<?php echo U('Home/Blog/index');?>"><span>论坛</span></a></li>
                    </ul>
                </div>
            </div>
            <div class="col-md-2 col-sm-2 text-right">
                <div class="link-group">
                    <a href="<?php echo ($user_manage["url1"]); ?>"><?php echo ($user_manage["value1"]); ?></a>
                    <span>|</span>
                    <a href="<?php echo ($user_manage["url2"]); ?>"><?php echo ($user_manage["value2"]); ?></a>
                </div>
            </div>
        </div>
    </div>
</header>
<div class="wrapper">
    <h1 class="reg-h1 text-center" >快&nbsp;速&nbsp;注&nbsp;册</h1>
    <h5 class="reg-h5 text-center" >开始一次发现美的旅程</h5>

    <form class="regform" action="<?php echo U('Home/User/register');?>" role="form" id="regForm" novalidate="novalidate">
        <div class="form-group">

            <input type="text" name="regUserName" id="regUserName" class="form-control" placeholder="用户名/邮箱"aria-required="true" aria-invalid="false" data-toggle="popover" data-placement="right" data-content=""/>
            <!--<i class="icon glyphicon glyphicon-user"></i>-->


        </div>
        <div class="form-group">
            <input type="password" name="regPassword" id="regPassword" class="form-control pwd" placeholder="密码" aria-required="true" aria-invalid="false" data-toggle="popover" data-placement="right" data-content=""/>
            <!--<i class="icon glyphicon glyphicon-eye-open"></i>-->
            <!--             <span class="msg msg-pwd"></span>
            -->
        </div>
        <div class="form-group">
            <input type="password" name="regPassword2" id="regPassword2" class="form-control pwd" placeholder="确认密码"
                   aria-required="true" aria-invalid="false"data-toggle="popover" data-placement="right" data-content=""/>
            <!--<i class="icon icon-password"></i>-->
        </div>
        <!--<div class="form-group clear-fix">-->
        <!--<div class="form-left">-->
        <!--<input type="text" name="ccap" id="ccap-text" class="form-control" placeholder="验证码"/>-->
        <!--<i class="icon"></i>-->
        <!--</div>-->
        <!--<div class="form-right">-->
        <!--<img class="ccap" src="" alt=""/>-->
        <!--</div>-->
        <!--</div>-->
        <input class="btn btn-primary form-control" type="button" id="submit" value="注册" />
        <!--         <span class="msg msg-reg"></span>
        -->    </form>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="/finder/Public/Js/bootstrap.min.js"></script>
<!-- <script src="/finder/Public/Static/validator/jquery.validator.js"></script> -->
<!-- <script src="/finder/Public/Static/validator/local/zh_CN.js"></script> -->
<!-- <script src="/finder/Public/Js/register.js"></script> -->
<script>
    /*  触发popover     selector=>选择器  msg=>显示内容  */
    function showPopover(selector,msg){
        $(selector).attr("data-content",msg);
        $(selector).attr("data-trigger",'showPop');

        $(selector).bind('showPop',  function(event) {
            /* Act on the event */
            $(selector).popover('show');
        });
        $(selector).trigger('showPop');
    }
    /*  判断是否为空  */
    function validata(){
        if($("#regUserName").val()==""){
            showPopover("#regUserName","在这里输入用户名哦");
            return false;
        }
        if($("#regPassword").val()==""){
            showPopover("#regPassword","密码在等你输入噢");
            return false;
        }
        if($("#regPassword2").val()==""){
            showPopover("#regPassword2","你是不是忘了点什么？");
            return false;
        }
        return true;
    }
    /*
     *信息验证
     */
    function isUsername(obj){
        reg = /^[a-z0-9_-]{4,20}$/;
        if(!reg.test(obj)){
            showPopover("#regUserName","你这名字太难听啦（4-20位英文、下划线、数字随意组合噢）");
            return false;
        }else{
            return true;
        }
    }
    function isPassword(selector,obj){
        reg = /^[a-z0-9_-]{6,18}$/;
        if(!reg.test(obj)){
            showPopover(selector,"密码都能错？（6-18位非空白字符串嘛:)）");
            return false;
        }else{
            return true;
        }
    }
    function isEquality(obj1,obj2,selector){
        if (obj1 != obj2) {
            showPopover(selector,"亲，确认密码错啦，还能不能好好玩耍？");
            return false;
        }else{
            return true;
        }
    }
    $(document).ready(function() {
        //初始化popover
        $(function () {
            $('[data-toggle="popover"]').popover()
        });
        $("input").attr("data-content","");
        $("input").attr("data-trigger",'abcd');
        //////////////////////////////////////////
        //console.log('1');
        $('#submit').on('click', function(event) {
            event.preventDefault();
            /* Act on the event */
            $("input").attr("data-content","");
            $("input").attr("data-trigger",'abcd');
            //console.log('2');
            username = $("#regUserName").val();
            pwd1     = $("#regPassword").val();
            pwd2     = $("#regPassword2").val();
            // a=isUsername(username);console.log('3');console.log(a);
            // b=isPassword("#regPassword",pwd1);
            // console.log('4');console.log(b);
            //;
            //isEquality(pwd1,pwd2,"#regPassword");
            if(validata() && isUsername(username) && isPassword("#regPassword",pwd1)
                    && isEquality(pwd1,pwd2,"#regPassword")){
                //console.log('nice');
                $("input").attr("data-content","");
                $("input").attr("data-trigger",'abcd');
                $param = $('#regForm').serialize();
                $action = $('#regForm').attr('action');
                $.post($action, $param, function(data) {
                    if(data['user_name']){
                        //console.log('4');
                        showPopover("#regUserName",data["user_name"]);
                        //console.log('5');
                        //$('.msg-name').html(data.user_name);
                    }
                    if(data.user_password){
                        $('.msg-pwd').html(data.user_password);
                    }
                    if(data.reg_msg){
                        $('.msg-reg').html(data.reg_msg);
                    }
                    if(data.status == 1){
                        location.href   =   data.url;
                    }
                },'json');

            }else{
                //console.log('bad');
                return;
            }
        });
    });


</script>


</body>
</html>